package protocol.JT905_2014;

public class Handle905_2014JT83 implements IHandle905_2014JT {
    @Override
    public String handle(JT_905_2014Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle8300(cmd);
            case 0x01:
                return handle8301(cmd);
            case 0x02:
                return handle8302(cmd);
            default:
                return "905:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8302(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:提问下发");
        builder.append("\r\n");
        int type = cmd.readInt(1);
        builder.append("\r\n");
        builder.append("标志："+type);
        builder.append("\r\n");
        builder.append("    紧急："+(type&0x01));
        builder.append("\r\n");
        builder.append("    预留"+(type>>1&0x01));
        builder.append("\r\n");
        builder.append("    终端显示器显示："+(type>>2&0x01));
        builder.append("\r\n");
        builder.append("    终端语音合成播读："+(type>>3&0x01));
        builder.append("\r\n");
        builder.append("    广告屏显示："+(type>>4&0x01));
        builder.append("\r\n");

        builder.append("问题ID:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("问题:"+cmd.readString(-1));
        builder.append("\r\n");
        builder.append("候选答案列表:");
        builder.append("\r\n");
        while (cmd.leftSize()>1){
            builder.append("    答案ID:"+cmd.readInt(1));
            builder.append("\r\n");
            builder.append("    答案内容:"+cmd.readString(-1));
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle8301(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:事件设置");
        builder.append("\r\n");
        int size = cmd.readInt(1);
        for (int i = 0;i<size;i++){
            builder.append("事件ID:"+cmd.readInt(1));
            builder.append("\r\n");
            builder.append("事件内容:"+cmd.readString(-1));
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle8300(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:文本信息下发");
        builder.append("\r\n");

        int type = cmd.readInt(1);
        builder.append("标志："+type);
        builder.append("\r\n");
        builder.append("    紧急："+(type&0x01));
        builder.append("\r\n");
        builder.append("    预留"+(type>>1&0x01));
        builder.append("\r\n");
        builder.append("    终端显示器显示："+(type>>2&0x01));
        builder.append("\r\n");
        builder.append("    终端语音合成播读："+(type>>3&0x01));
        builder.append("\r\n");
        builder.append("    广告屏显示："+(type>>4&0x01));
        builder.append("\r\n");

        builder.append("文本信息："+cmd.readString(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }
}
